# etcd common flags required to use etcdctl
#
# These variables have to be exported if you want to use etcdctl for
# debugging purposes (for example to use: `etcdctl cluster-health`).
# Use the following command to make these variables visible to
# etcdctl:
# set -a; source /etc/sysconfig/etcdctl; set +a

{% set cluster_ep = [] -%}
{% for _, addr in salt['mine.get']('roles:etcd', 'network.ip_addrs', tgt_type='grain').items() -%}
{% if cluster_ep.append( "https://" + addr[0] + ":2379") -%}
{% endif -%}
{% endfor -%}

ETCDCTL_ENDPOINT="{{ cluster_ep|join(',') }}"

# etcd v2 style flags
ETCDCTL_CA_FILE={{ pillar['ssl']['ca_file'] }}
ETCDCTL_CERT_FILE={{ pillar['ssl']['crt_file'] }}
ETCDCTL_KEY_FILE={{ pillar['ssl']['key_file'] }}

# etcd v3 style flags
ETCDCTL_CACERT={{ pillar['ssl']['ca_file'] }}
ETCDCTL_CERT={{ pillar['ssl']['crt_file'] }}
ETCDCTL_KEY={{ pillar['ssl']['key_file'] }}
